package com.sh.business.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
import com.aizuda.snailjob.common.core.enums.JobBlockStrategyEnum;
import com.sh.business.config.RabbitmqSender;
import com.sh.business.domain.User;
import com.sh.business.domain.UserOutInvest;
import com.sh.business.domain.bo.RepurchaseBo;
import com.sh.business.domain.dto.DelayMessageDto;
import com.sh.business.domain.form.PurchaseBo;
import com.sh.business.domain.vo.DailyInvestVo;
import com.sh.business.domain.vo.UserInvestStatisticsVo;
import com.sh.business.mapper.MiningMapper;
import com.sh.business.mapper.UserMapper;
import com.sh.business.mapper.UserOutInvestMapper;
import com.sh.business.service.facade.TransactionServiceFacade;
import com.sh.business.service.facade.UserFoundServiceFacade;
import com.sh.common.core.enums.*;
import com.sh.common.core.exception.ServiceException;
import com.sh.common.core.utils.*;
import com.sh.common.mybatis.core.page.TableDataInfo;
import com.sh.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sh.common.satoken.utils.LoginHelper;
import com.sh.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.sh.business.domain.bo.UserInvestBo;
import com.sh.business.domain.vo.UserInvestVo;
import com.sh.business.domain.UserInvest;
import com.sh.business.mapper.UserInvestMapper;
import com.sh.business.service.IUserInvestService;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import static com.sh.common.core.constant.BusinessConstants.COMPANY_ID;


/**
 * 用户投资记录Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-08
 */
@RequiredArgsConstructor
@Service
public class UserInvestServiceImpl implements IUserInvestService {

    private final UserInvestMapper baseMapper;
    private final UserMapper userMapper;
    private final RabbitmqSender rabbitmqSender;
    private final MiningMapper miningMapper;
    private final ISysConfigService iSysConfigService;
    private final UserFoundServiceFacade userFoundServiceFacade;
    private final TransactionServiceFacade transactionServiceFacade;
    private final UserOutInvestMapper userOutInvestMapper;

    @Override
    public void createAllJob() {
        List<UserInvest> userInvestList = baseMapper.selectList(Wrappers.<UserInvest>lambdaQuery().select(UserInvest::getId, UserInvest::getOrderSn, UserInvest::getCreateTime).eq(UserInvest::getStatus, TransferStatusEnum.CONFIRM_RECEIPT.getCode()).gt(UserInvest::getId, 1888785543420997633L));

        userInvestList.forEach(userInvest -> {

            CompletableFuture.runAsync(() -> {
                UserInvest update = new UserInvest();
                update.setId(userInvest.getId());

                // 获取createTime的时分秒
                Date createTime = userInvest.getCreateTime();
                System.out.println("orderSn:" + userInvest.getOrderSn() + ",时间：" + createTime);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(createTime);
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                int minute = calendar.get(Calendar.MINUTE);
                int second = calendar.get(Calendar.SECOND);

                // 构建cron表达式，每天执行
                String cronExpression = String.format("%d %d %d * * ?", second, minute, hour);

                Long jobId = SnailJobOpenApi.addClusterJob()
                        .setRouteKey(AllocationAlgorithmEnum.ROUND)
                        .setJobName(userInvest.getOrderSn() + "每日动态")
                        .setExecutorInfo("DailyDynamicSzpnAnnoJobExecutor")
                        .setExecutorTimeout(120)
                        .setDescription("add")
                        .setBlockStrategy(JobBlockStrategyEnum.DISCARD)
                        .setMaxRetryTimes(1)
                        .setTriggerType(TriggerTypeEnum.CRON)
                        .setTriggerInterval(cronExpression)
                        .addArgsStr("orderSn", userInvest.getOrderSn())
                        .setRetryInterval(3)
                        .execute();

                update.setJobId(jobId);

                baseMapper.updateById(update);
            }, Executors.newVirtualThreadPerTaskExecutor());
        });


        // 外部投资记录
        List<UserOutInvest> userOutInvestList = userOutInvestMapper.selectList(Wrappers.<UserOutInvest>lambdaQuery().select(UserOutInvest::getId, UserOutInvest::getOrderSn, UserOutInvest::getCreateTime));

        userOutInvestList.forEach(userOutInvest -> {
            CompletableFuture.runAsync(() -> {
                UserOutInvest update = new UserOutInvest();
                update.setId(userOutInvest.getId());

                // 获取createTime的时分秒
                Date createTime = userOutInvest.getCreateTime();
                System.out.println("orderSn:" + userOutInvest.getOrderSn() + ",时间：" + createTime);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(createTime);
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                int minute = calendar.get(Calendar.MINUTE);
                int second = calendar.get(Calendar.SECOND);


                // 构建cron表达式，每天执行
                String cronExpression = String.format("%d %d %d * * ?", second, minute, hour);

                Long jobId = SnailJobOpenApi.addClusterJob()
                        .setRouteKey(AllocationAlgorithmEnum.ROUND)
                        .setJobName(userOutInvest.getOrderSn() + "每日动态")
                        .setExecutorInfo("DailyDynamicSzpnAnnoJobExecutor")
                        .setExecutorTimeout(120)
                        .setDescription("add")
                        .setBlockStrategy(JobBlockStrategyEnum.DISCARD)
                        .setMaxRetryTimes(1)
                        .setTriggerType(TriggerTypeEnum.CRON)
                        .setTriggerInterval(cronExpression)
                        .addArgsStr("orderSn", userOutInvest.getOrderSn())
                        .setRetryInterval(3)
                        .execute();


                update.setJobId(jobId);

                userOutInvestMapper.updateById(update);
            }, Executors.newVirtualThreadPerTaskExecutor());

        });
    }

    @Override
    public void resendMqMsg() {
        List<UserInvest> userInvestList = baseMapper.query20250422Invest();

        System.out.println("补发消息");
        userInvestList.forEach(userInvest -> {
            Date createTime = userInvest.getCreateTime();
            // 使用 Calendar 加一天
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(createTime);
            calendar.add(Calendar.DATE, 1); // 加一天

            Date newDate = calendar.getTime();

            // 秒
            long secondsDifference = (newDate.getTime() - new Date().getTime()) / 1000;
            System.out.println(userInvest.getOrderSn() + "=" + secondsDifference);

            rabbitmqSender.sendDailyDynamicsTtlMsgManual(userInvest.getOrderSn(), secondsDifference);
        });

    }

    /**
     * 查询用户投资记录
     *
     * @param id 主键
     * @return 用户投资记录
     */
    @Override
    public UserInvestVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 分页查询用户投资记录列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 用户投资记录分页列表
     */
    @Override
    public TableDataInfo<UserInvestVo> queryPageList(UserInvestBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<UserInvest> lqw = buildQueryWrapper(bo);
        lqw.orderByDesc(UserInvest::getCreateTime);
        Page<UserInvestVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        result.getRecords().forEach(userInvestVo -> {
            User user = userMapper.selectById(userInvestVo.getUserId());
            userInvestVo.setMark(user.getMark());
        });
        return TableDataInfo.build(result);
    }

    @Override
    public TableDataInfo<UserInvestVo> queryInvestList(UserInvestBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(baseMapper.queryInvestList(bo, pageQuery.build()));
    }

    @Override
    public UserInvestStatisticsVo queryUserInvestStatistics(UserInvestBo bo) {
        bo.setStatus(TransferStatusEnum.CONFIRM_RECEIPT.getCode());
        return baseMapper.queryUserInvestStatistics(bo);
    }

    @Override
    public TableDataInfo<DailyInvestVo> queryDailyInvest(PageQuery pageQuery) {
        return TableDataInfo.build(baseMapper.queryDailyInvest(pageQuery.build()));
    }

    /**
     * 查询符合条件的用户投资记录列表
     *
     * @param bo 查询条件
     * @return 用户投资记录列表
     */
    @Override
    public List<UserInvestVo> queryList(UserInvestBo bo) {
        LambdaQueryWrapper<UserInvest> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<UserInvest> buildQueryWrapper(UserInvestBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<UserInvest> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getUserId() != null, UserInvest::getUserId, bo.getUserId());
        lqw.eq(StringUtils.isNotBlank(bo.getOrderSn()), UserInvest::getOrderSn, bo.getOrderSn());
        lqw.eq(bo.getAmount() != null, UserInvest::getAmount, bo.getAmount());
        lqw.eq(StringUtils.isNotBlank(bo.getTxHash()), UserInvest::getTxHash, bo.getTxHash());
        lqw.eq(bo.getStatus() != null, UserInvest::getStatus, bo.getStatus());
        lqw.eq(bo.getTransferTime() != null, UserInvest::getTransferTime, bo.getTransferTime());
        lqw.eq(StringUtils.isNotBlank(bo.getFromAddress()), UserInvest::getFromAddress, bo.getFromAddress());
        lqw.eq(StringUtils.isNotBlank(bo.getToAddress()), UserInvest::getToAddress, bo.getToAddress());
        lqw.eq(StringUtils.isNotBlank(bo.getNotifyData()), UserInvest::getNotifyData, bo.getNotifyData());
        lqw.between(bo.getStartTime() != null && bo.getEndTime() != null, UserInvest::getCreateTime, bo.getStartTime(), bo.getEndTime());
        return lqw;
    }

    /**
     * 新增用户投资记录
     *
     * @param bo 用户投资记录
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(UserInvestBo bo) {
        // 测试时使用
        /*User user = userMapper.selectById(LoginHelper.getUserId());
        UserInvest add = new UserInvest();
        add.setUserId(user.getUserId());
        add.setOrderSn(OrderSnUtil.generateOrderSn(OrderTypeEnum.TZ));
        add.setFromAddress(user.getWalletAddress());
        add.setStatus(TransferStatusEnum.WAIT_CONFIRM.getCode());
        add.setTxHash(bo.getTxHash());
        add.setAmount(bo.getAmount());

        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
            if (!user.getIsActive()) {
                User update = new User();
                update.setUserId(user.getUserId());
                update.setIsActive(true);
                userMapper.updateById(update);
            }
            Mining mining = miningMapper.queryByPrice(add.getAmount());

            // 奖励算力
            userFoundServiceFacade.modifyUserFound(user.getUserId(),
                add.getOrderSn(),
                add.getTxHash(),
                UserFoundEnum.COMPUTILITY,
                TransferFlagEnum.TRANSFER_IN,
                mining.getComputility(),
                TransferDescEnum.PURCHASE_MINING.getCode().toString(),
                null);
            // 增加本人业绩
            userFoundServiceFacade.changeUserFound(user.getUserId(), UserFoundEnum.SELF_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, mining.getPrice());

            // 发送异步处理消息
            rabbitmqSender.sendCallBackMsg(add.getTxHash());
        }
        return flag;*/

        // 正式时使用
        User user = userMapper.selectById(LoginHelper.getUserId());
        UserInvest add = new UserInvest();
        add.setUserId(user.getUserId());
        add.setOrderSn(OrderSnUtil.generateOrderSn(OrderTypeEnum.TZ));
        add.setFromAddress(user.getWalletAddress());
        add.setStatus(TransferStatusEnum.WAIT_CONFIRM.getCode());
        add.setTxHash(bo.getTxHash());
        add.setAmount(bo.getAmount());

        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }

        // 发送延迟查询消息
        DelayMessageDto delayMessageDto = new DelayMessageDto();
        delayMessageDto.setTxHash(bo.getTxHash());
        delayMessageDto.setType(MessageTypeEnum.INVEST.getCode());
        delayMessageDto.setCreateTime(DateUtils.getNowDate());
        // 第一次30秒后查询
        rabbitmqSender.sendTtlMsg(delayMessageDto, 30 * 1000L);

        return flag;
    }

    @Override
    public Boolean purchase(PurchaseBo bo) {
        // szpn价格
        BigDecimal szpnPrice = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.szpn.price"));
        BigDecimal mininumUsdtAmount = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.charge.minimum.usdt.amount"));
        String toAddress = Convert.toStr(iSysConfigService.selectConfigByKey("bsc.toAddress"));


        User user = userMapper.selectById(LoginHelper.getUserId());

        switch (PurchaseTypeEnum.of(bo.getPurchaseType())) {
            case USDT -> {
                if (StringUtils.isBlank(bo.getTxHash())) {
                    throw new ServiceException("txHash can not be empty");
                }
                if (bo.getPurchaseAmount().compareTo(mininumUsdtAmount) < 0) {
                    throw new ServiceException("minimum amount : " + mininumUsdtAmount);
                }
                UserInvest userInvest = new UserInvest();
                userInvest.setUserId(user.getUserId());
                userInvest.setOrderSn(OrderSnUtil.generateOrderSn(OrderTypeEnum.TZ));
                userInvest.setFromAddress(user.getWalletAddress());
                userInvest.setStatus(TransferStatusEnum.WAIT_CONFIRM.getCode());
                userInvest.setTxHash(bo.getTxHash());
                userInvest.setPurchaseAmount(bo.getPurchaseAmount());
                userInvest.setAmount(bo.getPurchaseAmount());
                userInvest.setToAddress(toAddress);
                userInvest.setType(bo.getPurchaseType());

                baseMapper.insert(userInvest);

                // 发送延迟查询消息
                DelayMessageDto delayMessageDto = new DelayMessageDto();
                delayMessageDto.setTxHash(bo.getTxHash());
                delayMessageDto.setType(MessageTypeEnum.INVEST.getCode());
                delayMessageDto.setCreateTime(DateUtils.getNowDate());
                // 第一次30秒后查询
                rabbitmqSender.sendTtlMsg(delayMessageDto, 30 * 1000L);
            }
            case WALLET_USDT -> {
                if (bo.getPurchaseAmount().compareTo(mininumUsdtAmount) < 0) {
                    throw new ServiceException("minimum amount : " + mininumUsdtAmount);
                }
                if (user.getUsdt().compareTo(bo.getPurchaseAmount()) < 0) {
                    throw new ServiceException("insufficient balance");
                }
                UserInvest userInvest = new UserInvest();
                userInvest.setUserId(user.getUserId());
                userInvest.setOrderSn(OrderSnUtil.generateOrderSn(OrderTypeEnum.TZ));
                userInvest.setFromAddress(user.getWalletAddress());
                userInvest.setStatus(TransferStatusEnum.CONFIRM_RECEIPT.getCode());
                userInvest.setTxHash(BlockChainUtils.generatorTxHash());
                userInvest.setPurchaseAmount(bo.getPurchaseAmount());
                userInvest.setAmount(bo.getPurchaseAmount());
                userInvest.setToAddress(toAddress);
                userInvest.setType(bo.getPurchaseType());

                baseMapper.insert(userInvest);
                // 扣除钱包中的usdt
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_OUT,
                    bo.getPurchaseAmount(),
                    TransferDescEnum.PURCHASE.getCode().toString(),
                    null);


                // 激活链接及节点
                transactionServiceFacade.activeAndNode(user, userInvest);

                // 获得空投及算力
                userFoundServiceFacade.airdropAndComputility(userInvest);

                userFoundServiceFacade.changeUserFound(user.getUserId(), UserFoundEnum.SELF_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, userInvest.getAmount());

                // 发送异步处理消息
                rabbitmqSender.sendCallBackMsg(userInvest.getTxHash());
            }
            case WALLET_SZPN -> {
                BigDecimal amount = NumberUtil.mul(bo.getPurchaseAmount(), szpnPrice);
                if (amount.compareTo(mininumUsdtAmount) < 0) {
                    throw new ServiceException("minimum amount : " + mininumUsdtAmount);
                }
                if (user.getTransferSzpn().compareTo(bo.getPurchaseAmount()) < 0) {
                    throw new ServiceException("insufficient balance");
                }
                UserInvest userInvest = new UserInvest();
                userInvest.setUserId(user.getUserId());
                userInvest.setOrderSn(OrderSnUtil.generateOrderSn(OrderTypeEnum.TZ));
                userInvest.setFromAddress(user.getWalletAddress());
                userInvest.setStatus(TransferStatusEnum.CONFIRM_RECEIPT.getCode());
                userInvest.setTxHash(BlockChainUtils.generatorTxHash());
                userInvest.setPurchaseAmount(bo.getPurchaseAmount());
                userInvest.setAmount(amount);
                userInvest.setToAddress(toAddress);
                userInvest.setType(bo.getPurchaseType());

                baseMapper.insert(userInvest);
                // 扣除钱包中的szpn
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.TRANSFER_SZPN,
                    TransferFlagEnum.TRANSFER_OUT,
                    bo.getPurchaseAmount(),
                    TransferDescEnum.PURCHASE.getCode().toString(),
                    null);
                // 转到公司钱包
                userFoundServiceFacade.modifyUserFound(COMPANY_ID,
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.TRANSFER_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        bo.getPurchaseAmount(),
                        TransferDescEnum.COMPANY_RECOVERY.getCode().toString(),
                        null);

                // 激活链接及节点
                transactionServiceFacade.activeAndNode(user, userInvest);

                // 获得空投及算力
                userFoundServiceFacade.airdropAndComputility(userInvest);

                userFoundServiceFacade.changeUserFound(user.getUserId(), UserFoundEnum.SELF_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, amount);

                // 发送异步处理消息
                rabbitmqSender.sendCallBackMsg(userInvest.getTxHash());
            }
        }
        return true;
    }

    @Override
    public Boolean repurchase(RepurchaseBo bo) {
        User user = userMapper.selectById(LoginHelper.getUserId());
        BigDecimal price = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.szpn.price"));
        BigDecimal szpnAmount = NumberUtil.div(bo.getAmount(), price).setScale(6, BigDecimal.ROUND_DOWN);

        if (user.getRepurchaseUsdt().compareTo(bo.getAmount()) < 0) {
            throw new ServiceException("usdt insufficient balance");
        }
        if (user.getTransferSzpn().compareTo(szpnAmount) < 0) {
            throw new ServiceException("szpn insufficient balance");
        }

        UserInvest userInvest = new UserInvest();
        userInvest.setUserId(user.getUserId());
        userInvest.setOrderSn(OrderSnUtil.generateOrderSn(OrderTypeEnum.TZ));
        userInvest.setTxHash(BlockChainUtils.generatorTxHash());
        userInvest.setType(PurchaseTypeEnum.WALLET_SZPN.getType());
        userInvest.setPurchaseAmount(szpnAmount);
        userInvest.setAmount(bo.getAmount());
        userInvest.setUsdtAmount(bo.getAmount());
        userInvest.setStatus(TransferStatusEnum.CONFIRM_RECEIPT.getCode());
        userInvest.setFromAddress(user.getWalletAddress());
        userInvest.setToAddress(Convert.toStr(iSysConfigService.selectConfigByKey("bsc.toAddress")));
        baseMapper.insert(userInvest);

        // todo:没写完

        // 扣除钱包中的szpn
        userFoundServiceFacade.modifyUserFound(user.getUserId(),
            userInvest.getOrderSn(),
            userInvest.getTxHash(),
            UserFoundEnum.TRANSFER_SZPN,
            TransferFlagEnum.TRANSFER_OUT,
            szpnAmount,
            TransferDescEnum.PURCHASE.getCode().toString(),
            null);
        // 转到公司钱包
        userFoundServiceFacade.modifyUserFound(COMPANY_ID,
            userInvest.getOrderSn(),
            userInvest.getTxHash(),
            UserFoundEnum.TRANSFER_SZPN,
            TransferFlagEnum.TRANSFER_IN,
            szpnAmount,
            TransferDescEnum.COMPANY_RECOVERY.getCode().toString(),
            null);

        // 扣除钱包中的szpn
        userFoundServiceFacade.modifyUserFound(user.getUserId(),
            userInvest.getOrderSn(),
            userInvest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_OUT,
            userInvest.getUsdtAmount(),
            TransferDescEnum.PURCHASE.getCode().toString(),
            null);
        // 转到公司钱包
        userFoundServiceFacade.modifyUserFound(COMPANY_ID,
            userInvest.getOrderSn(),
            userInvest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            userInvest.getUsdtAmount(),
            TransferDescEnum.COMPANY_RECOVERY.getCode().toString(),
            null);

        // 激活链接及节点
        transactionServiceFacade.activeAndNode(user, userInvest);

        // 获得空投及算力
        userFoundServiceFacade.airdropAndComputility(userInvest);

        userFoundServiceFacade.changeUserFound(user.getUserId(), UserFoundEnum.SELF_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, bo.getAmount());

        // 发送异步处理消息
        rabbitmqSender.sendCallBackMsg(userInvest.getTxHash());

        return true;
    }

    /**
     * 修改用户投资记录
     *
     * @param bo 用户投资记录
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(UserInvestBo bo) {
        UserInvest update = MapstructUtils.convert(bo, UserInvest.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(UserInvest entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 校验并批量删除用户投资记录信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteByIds(ids) > 0;
    }
}
